package net.zrnecko.km;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import net.zrnecko.km.client.GreetingService;
import net.zrnecko.km.client.LoginService;
import net.zrnecko.km.client.PersistenceService;
import net.zrnecko.km.entity.DataFileProcessor;
import net.zrnecko.km.entity.DataFileProcessorImpl;
import net.zrnecko.km.server.GreetingServiceImpl;
import net.zrnecko.km.server.LoginServiceImpl;
import net.zrnecko.km.server.PersistenceServiceImpl;

import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;

import com.google.inject.servlet.ServletModule;

public class KalicMastersServletModule extends ServletModule {

	@Override
	protected void configureServlets() {
		serve("/kalicmasters/upload").with(UploadServlet.class);
		serve("/kalicmasters/remote").with(GuiceRemoteServiceServlet.class);
		serve("/kalicmasters/login").with(GuiceRemoteServiceServlet.class);
		// TODO may be removed once admin functionality is moved to KM module
		serve("/admin/remote").with(GuiceRemoteServiceServlet.class);
		serve("/net.zrnecko.km.admin.Admin/remote").with(GuiceRemoteServiceServlet.class);

		// persistence factory initialization
		bind(EntityManagerFactory.class)
				.toInstance(
						Persistence
								.createEntityManagerFactory("transactions-optional"));
		
		bind(Mapper.class)
				.toInstance(new DozerBeanMapper());

		// cannot use @ImplementedBy
		bind(GreetingService.class).to(GreetingServiceImpl.class);
		bind(PersistenceService.class).to(PersistenceServiceImpl.class);
		bind(DataFileProcessor.class).to(DataFileProcessorImpl.class);
		bind(LoginService.class).to(LoginServiceImpl.class);

	}

}
